// 2025/4/5
// https://leetcode.cn/problems/palindrome-linked-list/description/?envType=study-plan-v2&envId=top-100-liked
// 回文链表

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
    public:
        bool isPalindrome(ListNode* head) {
            int count = 0;
            ListNode* cur = head;
            stack<int> st;
            while(cur)
            {
                count++;
                st.push(cur->val);
                cur = cur->next;
            }
            count /= 2;
            while(count--)
            {
                if(head->val != st.top())
                    return false;
                head = head->next;
                st.pop();
            }
            return true;
        }
    };